package com.xlh.openai;

import java.util.Date;

public class MyThread extends Thread {

    private Object lock;

    public MyThread(Object lock) {
        this.lock = lock;
    }

    public void run() {
        // 锁住时间
        synchronized(lock) {
            try {
                Thread.sleep(1000);
                System.out.println(new Date().getSeconds());
                System.out.println("是否锁住了对象");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
